package com.ziguang.redwood.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Record;
import com.ziguang.redwood.web.service.ProductCenterService;

@ControllerBind(controllerKey = "/webProduct", viewPath = "/")
public class ProductCenterController extends Controller{

	/**
	 * 获取产品信息
	 */
	public void index(){
		Map map = new HashMap();
		String typeId = this.getPara("typeId");
		String pageNum = this.getPara("pageNum");
		if(pageNum == null){
			pageNum = "1";
		}
		Integer num = Integer.parseInt(pageNum);
		if(num <= 0){
			num = 1;
		}
		String typeName = this.getPara("typeName");
		List<Record> product = ProductCenterService.me.findProduct(typeId,num);
		setAttr("productList", product);
		List<Record> productType = ProductCenterService.me.findProductType();
		setAttr("productType", productType);
		Record totalPage = ProductCenterService.me.findCount(typeId);
		setAttr("totalPage", totalPage);
		setAttr("pageNum", num);
		setAttr("typeName", typeName);
		render("product_center.html");
		
	}
	
	/**
	 * 获取产品详细信息
	 */
	public void productDetail(){
		String id = this.getPara("id");
		Record productDetail = ProductCenterService.me.findProductDetail(id);
		List<Record> productType = ProductCenterService.me.findProductType();
		setAttr("productType", productType);
		setAttr("productDetail",productDetail);
		render("product_detail.html");
		
	}
	
}
